﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _013_WCFClient
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                _013_WCFService.IServerInterface srv = new _013_WCFService.ServerInterfaceClient();

                int command = 0;
                HashSet<int> requests = new HashSet<int>();


                do
                {
                    Console.WriteLine("Menu");
                    Console.WriteLine("1 - Exit");
                    Console.WriteLine("2 - Add Array");
                    Console.WriteLine("3 - Show Servers Array");
                    Console.WriteLine("4 - Process");
                    Console.WriteLine("5 - Show result");

                    command = Int32.Parse(Console.ReadLine());

                    switch (command)
                    {
                        case 2:
                            Console.WriteLine("Enter array size:");
                            int size = Int32.Parse(Console.ReadLine());
                            if (size > 0)
                            {
                                int []array = new int[size];
                                for (int i = 0; i < size; i++)
                                {
                                    Console.Write("Enter element {0}:", i);
                                    array[i] = Int32.Parse(Console.ReadLine());
                                }
                                Console.Write("Sending request to server ...");
                                int rq_index = srv.AddRequest(array);
                                Console.WriteLine("{0}", rq_index);
                                requests.Add(rq_index);
                            }
                            break;
                        case 3:
                            {
                                Console.WriteLine("We have following requests:");
                                foreach (int rq_id in requests) Console.Write("{0} ", rq_id);
                                Console.WriteLine();
                                int rq_index = Int32.Parse(Console.ReadLine());

                                int[] array = srv.GetRequest(rq_index);
                                foreach (int a in array) Console.Write("{0} ", a);
                                Console.WriteLine();

                            }
                            break;
                        case 4:
                            {
                                Console.WriteLine("We have following requests:");
                                foreach (int rq_id in requests) Console.Write("{0} ", rq_id);
                                Console.WriteLine();
                                int rq_index = Int32.Parse(Console.ReadLine());
                                srv.ProcessRequest(rq_index);
                                Console.WriteLine("Done");
                            }
                            break;
                        case 5:
                            {
                                Console.WriteLine("We have following requests:");
                                foreach (int rq_id in requests) Console.Write("{0} ", rq_id);
                                Console.WriteLine();
                                int rq_index = Int32.Parse(Console.ReadLine());

                                int[] array = srv.GetResponse(rq_index);
                                foreach (int a in array) Console.Write("{0} ", a);
                                Console.WriteLine();

                            }
                            break;
                    }
                } while (command != 1);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
    }
}
